program Newton_RaphsonMethod
implicit none
real*8 epsilon, x, answer, error
integer*2 count
parameter (epsilon = 1.E-6)
print*, "Enter starting values ..."
read*,x
call Newton_Raphson(epsilon, x, answer, error, count)
if (error .EQ. -1) then
   print*, "error not reached ... the method failed."
else
   print*, "After ", count, " iterations,"
   print*, "a zero was found at ", answer
end if
end

subroutine ex(x,y)
implicit none
real*8 x,y
y = 1 + x + x**2/2 + x**3/6 + x**4/24
end

subroutine Newton_Raphson(eps, x, answer, error,count)
implicit none
real*8 eps, x, x0, x1, x2,error,answer
integer*2 count
error = 1;
count=0
do while (error > eps)
count = count+1
x0 = x
call f(x,x1)
call f_a(x,x2)
x = x - (x1/x2)
error = abs(x-x0) 
print*, count,"\t\t",x,"\t\t",error
end do
answer = x
end

subroutine f(x,z)
implicit none
real*8 x,y,z
call ex(x,y)
z = y - 5*x**2
end

subroutine f_a(x,z)
implicit none
real*8 x,y,z
call ex(x,y)
z = y - 10*x
end
